﻿using System;
using TaobaoAPIDAO.App_Code;
using Top.Api.Domain;
using Top.Api.Response;
using Top.Api.Request;

namespace TaobaoAPIDAO.TopApiDao
{
    public class TradeRateApiDao : BaseTopApiDao
    {
        #region public void TaobaoTraderateAdd(string, long, long, string, string, string, Boolean) 新增单个评价
        /// <summary>
        /// 新增单个评价:在评价之前需要对订单成功的时间进行判定（end_time）,如果超过15天，不用再通过该接口进行评价) 
        /// </summary>
        /// <param name="sessionKey"></param>
        /// <param name="Tid">交易ID:必须</param>
        /// <param name="Oid">子订单ID:可选</param>
        /// <param name="Result">评价结果,可选值:good(好评),neutral(中评),bad(差评):必须</param>
        /// <param name="Role">评价者角色,可选值:seller(卖家),buyer(买家):必须</param>
        /// <param name="Content">评价内容,最大长度: 500个汉字</param>
        /// <param name="Anony">是否匿名,卖家评不能匿名。可选值:true(匿名),false(非匿名)</param>
        public void TaobaoTraderateAdd(string sessionKey, long Tid, long Oid, string Result, string Role, string Content, Boolean Anony)
        {
            TraderateAddRequest req = new TraderateAddRequest();
            req.Tid = Tid;
            req.Oid = Oid;
            req.Result = Result;
            req.Role = Role;
            req.Content = Content;
            req.Anony = Anony;
            TraderateAddResponse response = myclient.Execute(req, sessionKey);
        }
        #endregion

        #region  public void TaobaoTraderateListAdd(string, long, long, string, string, string, Boolean)  针对父子订单新增批量评价
        /// <summary>
        /// 针对父子订单新增批量评价:在评价之前需要对订单成功的时间进行判定（end_time）,如果超过15天，不用再通过该接口进行评价) 
        /// </summary>
        /// <param name="sessionKey"></param>
        /// <param name="Tid">交易ID:必须</param>
        /// <param name="Oid">子订单ID:可选</param>
        /// <param name="Result">评价结果,可选值:good(好评),neutral(中评),bad(差评)</param>
        /// <param name="Role">评价者角色,可选值:seller(卖家),buyer(买家)</param>
        /// <param name="Content">评价内容,最大长度: 500个汉字</param>
        /// <param name="Anony">是否匿名,卖家评不能匿名。可选值:true(匿名),false(非匿名)</param>
        public void TaobaoTraderateListAdd(string sessionKey, long Tid, long Oid, string Result, string Role, string Content, Boolean Anony)
        {
            TraderateListAddRequest req = new TraderateListAddRequest();
            req.Tid = Tid;
            req.Result = Result;
            req.Role = Role;
            req.Content = Content;
            req.Anony = Anony;
            req.Oid = Oid;
            TraderateListAddResponse response = myclient.Execute(req, sessionKey);
        }

        #endregion

        #region public TraderatesGetResponse TaobaoTraderatesGet(string, string,long, string, DateTime, DateTime)搜索评价信息
        /// <summary>
        /// 搜索评价信息
        /// </summary>
        /// <param name="sessionKey"></param>
        /// <param name="rateType"></param>
        /// <param name="tid"></param>
        /// <param name="role"></param>
        /// <param name="startDate"></param>
        /// <param name="endDate"></param>
        public TraderatesGetResponse TaobaoTraderatesGet(string sessionKey,  DateTime startDate, DateTime endDate,string rateType, long tid, string role)
        {
            //实例化具体API对应的Request类
            TraderatesGetRequest req = new TraderatesGetRequest();
            req.Fields = TradeRateApiFiled.TradeRateApiField;
            req.RateType = "get";
            req.Role = "buyer";
            //判断参数评价类型是否为空,不为空则追加该条件
            if (!string.IsNullOrEmpty(rateType))
            {
                req.RateType = rateType;
            }
            //判断角色是否为空
            if (!string.IsNullOrEmpty(role))
            {
                req.Role = role;
            }
            //判断交易订单ID是否为空
            if (tid!=long.MinValue)
            {
                req.Tid = tid;
            }

            //判断起止时间是否为默认值。
            if (startDate !=DateTime.MinValue&&endDate !=DateTime.MinValue)
            {
                req.StartDate = startDate;
                req.EndDate = endDate;
            }
            
            //调用API取得需要的数据
            TraderatesGetResponse response = myclient.Execute(req, sessionKey);
            return response; 
        }
        #endregion

        #region public TraderatesSearchResponse TaobaoTraderatesSearch(long, string)商品评价查询接口：通过商品id查询对应的评价信息
        /// <summary>
        /// 商品评价查询接口：通过商品id查询对应的评价信息
        /// </summary>
        /// <param name="numId"></param>
        /// <param name="SellerNick"></param>
        /// <returns></returns>
        public TraderatesSearchResponse TaobaoTraderatesSearch(long numId, string SellerNick)
        {
            TraderatesSearchRequest req = new TraderatesSearchRequest();
            //商品的数字id 
            req.NumIid = numId;
            //商品所属的卖家nick 
            req.SellerNick = SellerNick;

            TraderatesSearchResponse response = myclient.Execute(req);
            return response;
        }
        #endregion

    }
}
